﻿using MediatR;
using SlaughterItem.Common.Domains.PORk;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.POOK.DelWhitePork
{
    /// <summary>
    /// 删除白条称重明细表
    /// </summary>
    public class DelWhitePorkHandler : IRequestHandler<DelWhitePorkCommand, Result>
    {
        public DelWhitePorkHandler(IBaseRepository<WhiteporkData> whiteporkDataRepository)
        {
            WhiteporkDataRepository = whiteporkDataRepository;
        }

        public IBaseRepository<WhiteporkData> WhiteporkDataRepository { get; set; }
        public async Task<Result> Handle(DelWhitePorkCommand request, CancellationToken cancellationToken)
        {
           var result= new Result() { Code=(int)CommonErrorCode.Update};
            var list = WhiteporkDataRepository.GetAll().FirstOrDefault(x => x.WhiteWeighingId == request.WhiteWeighingId);
            list.IsDel=true;
            var DelNum=WhiteporkDataRepository.Update(list);
            if (DelNum > 0)
            {
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
